package com.woyou.ui.fragment;

import com.citaq.ideliver.R;
import com.woyou.ui.api.TryAgain;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 数据出错的提示View
 * @author longtao.li
 *
 */
public class HintView extends RelativeLayout implements OnClickListener {

	private TextView hintText ;
	private TryAgain listener;
	private View tryAgain;
	private View ivHint;
	
	public void setTryAgainListener(TryAgain l){
		this.listener = l;
	}
	
	public HintView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	

	public HintView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public HintView(Context context) {
		super(context);
		init();
	}
	
	private void init() {
		View.inflate(getContext(), R.layout.layout_hint, this);
		ivHint = findViewById(R.id.iv_hint);
		hintText = (TextView) findViewById(R.id.tv_hint);
		tryAgain = findViewById(R.id.try_again);
		tryAgain.setOnClickListener(this);
	}
	
	public void setHint(String hint){
		hintText.setText(hint);
	}
	
	public void disTryAgain(){
		tryAgain.setVisibility(View.GONE);
		ivHint.setVisibility(View.GONE);
	}
	
	public void openButton(){
		tryAgain.setVisibility(View.VISIBLE);
		ivHint.setVisibility(View.VISIBLE);
	}
	
	

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.try_again:
			if( listener!=null ){
				listener.tryAgain();
			}
			break;

		default:
			break;
		}
		
	}

}
